<?php
include_once '../includes/common.php';
if($islogin2==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
if(isset($_GET['id'])) {
$id=isset($_GET['id'])?intval($_GET['id']):sysmsg("参数错误",2,'./shop.php',true);
$row=$DB->get_row("SELECT * FROM authguao_shop WHERE id='{$id}' limit 1");
if(!$row)sysmsg("授权平台不存在该商品",2,'./shop.php',true);
$title='商品详情页';
include_once './header.php';
if($conf['Market_open']!=1)showmsg('错误', '授权平台未开放商城系统！', 4, './');
if ($row['type'] == 1) {
    $type_name = '模板类';
} else if ($row['type'] == 2) {
    $type_name = '插件类';
} else if ($row['type'] == 3) {
    $type_name = '其他类';
} else {
    $type_name = '未知类';
}
$shopimg = explode(',', $row['image']);
if ($row['uid'] == 1) {
    if($conf['admin_qq']){
        $qq=$conf['admin_qq'];
    }else{
        $qq=$conf['kfqq'];
    }
} else {
    $user = $DB->get_row("select * from authguao_user where uid='" . $row['uid'] . "' limit 1");
    $qq = $user['qq'];
}
if ($row['active'] == 1) {
    $text = '<font color="green">管理员已审核过此商品</font>';
} else {
    if ($conf['Market_trade_type'] == 1) {
        $text = '未审核,用户自由交易商品';
    } else {
        $text = '未审核该商品';
    }
}
$rows=$DB->get_row("SELECT * FROM authguao_praise WHERE tid='{$id}' and uid='{$userrow['uid']}' limit 1");
if($rows){
    $onclick = "layer.msg('已经赞过了哦!')";
    $praise_text = '已赞';
}else{
    $onclick = "praise(".$id.")";
    $praise_text = '赞一下';
}
$shop_log = $DB->get_row("select * from authguao_shoplog where tid='" . $id . "' and uid='" . $userrow['uid'] . "' limit 1");
if ($shop_log) {
    $alt = '<font onclick="upaet('.$id.')">获取购买内容</font>';
} else {
    if ($row['money'] == '0.00') {
        $alt = '<font onclick="store_log('.$id.')">免费获取</font>';
    } else {
        $alt = '<font onclick="store_log('.$id.')" color="red">购买</font>';
    }
}
if ($row['proid'] == 999999999) {
    $system = '<a style="color:#80CBC4">'.$row['system_name'].'</a>';
} else {
    $program = $DB->get_row("select * from authguao_program where id='" . $row['proid'] . "' limit 1");
    $system = '<a style="color:#FF8A80">'.$program['name'].'</a>';
}
$sjjscount=$DB->count("SELECT count(*) from authguao_shop WHERE uid='{$row['uid']}'");
?>
  <link href="https://cdn.staticfile.org/Swiper/4.5.1/css/swiper.min.css" rel="stylesheet">
  <link href="../assets/layui/style/admin.css" rel="stylesheet" media="all">
  <link href="../assets/layui/style/template.css" rel="stylesheet" media="all">
  <style>
    .auth_input {
        width: calc(100% - 3em);
        height: 2.4em;
        text-align: left;
        margin-top: 0.4em;
        border: none;
        background-color: whitesmoke;
        text-indent: 1em;
        border-radius: 0.3em 0.0em 0em 0.3em;
    }

    .auth_colas {
        width: 16em;
        height: 3em;
        background-color: white;
        display: flex;
        float: right;
        padding: 0;
        margin: 0;
        border-radius: 0.5em;
        margin-right: 0.5em;
        transition: all 0.3s;
    }

    .auth_colas a {
        width: 3em;
        height: 2.4em;
        background-color: whitesmoke;
        margin-top: 0.4em;
        border-radius: 0.0em 0.3em 0.3em 0.0em;
        cursor: pointer;
    }

    .auth_colas a:hover {
        color: mediumslateblue;
    }

    .fleott a {
        width: auto;
        text-align: center;
        height: 3em;
        line-height: 3em;
        display: flex;
        float: left;
        display: block;
        cursor: pointer;
        transition: all 0.3s;
        padding: 0 1em 0 1em;
    }

    .fleott a:hover {
        color: #f20d0d;
    }

    @media only screen and (min-width: 700px) {
        .auth_colas {
            width: 35em;
        }
    }

    .auth_active {
        background: rgba(242, 13, 13, .06);
        border-radius: 6px;
        font-weight: 700;
        color: #f20d0d;
    }

    .auth_biaot {
        position: absolute;
        top: 0em;
        right: 0em;
        height: 2em;
        display: block;
    }

    .auth_left {
        position: absolute;
        top: 1.35em;
        right: 0em;
        height: 2em;
        display: block;
    }
    .auth_div {
        overflow: hidden;
    }

    @media only screen and (min-width: 700px) {
        .auth_div {
            margin-top: 0.5em;
        }
    }

    .auth_a_image {
        height: 17em !important;
        display: block;
        overflow: hidden;
    }

    .auth_image {
        width: 100%;
        transition: all 0.4s;
    }

    .auth_image:hover {
        -webkit-transform: scale(2) rotate(3deg);
        -moz-transform: scale(2) rotate(3deg);
        -o-transform: scale(2) rotate(3deg);
    }

    .layui-layer-imgbar {
        display: block !important;
    }
    .image_body {
        height: 100px;
        overflow: hidden;
        padding: 0;
        padding-bottom: 1rem;
        text-align: center;
        margin-bottom: 1rem;
    }
    </style>
<style>
    .CodeMirror {
        height: 100%;
    }

    #copy-btn {
        color: white;
    }

    #code2 {
        width: 100%;
        height: 1px;
        border: none;
        opacity: 0.01;
    }
</style>
    <div class="layui-row layui-col-space8">
        <div class="layui-col-xs12 layui-col-sm8">
            <div class="layadmin-homepage-panel layadmin-homepage-shadow">
                <div class="layui-card text-center">
                    <div class="layui-card-body">
                        <div class="swiper-container" style="width: 100%;height: 23em;margin-bottom: 1em;">
                            <div class="swiper-wrapper">
                            <?php
                            foreach($shopimg as $image){
                                echo '<div class="swiper-slide"><img onclick="image_msg('.$id.')" src="'.$image.'" style="max-width: 100%;max-height: 20em" /></div>';
                            }
                            ?>
                            </div>
                            <!-- Add Pagination -->
                            <div class="swiper-pagination"></div>
                        </div>
                        <h4 class="layadmin-homepage-font"><?php echo $row['name'] ?></h4>
                        <p class="layui-word-aux" style="width: 90%;margin: auto;"><?php echo $row['recommend'] ?></p>
                        <div class="layadmin-homepage-pad-ver">
                            <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-sm"><?php echo $alt?></a>
                            <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-sm" id="dda_dianz" onclick="<?php echo $onclick?>">
                                <i class="layui-icon layui-icon-praise"></i>
                                <span id="dianz"><?php echo $praise_text?>(<?php echo $row['praise']?>)</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm4">
            <div class="layadmin-homepage-panel layadmin-homepage-shadow">
                <div class="layui-card">
                    <div class="layui-card-header">
                        卖家<?php echo qqname($qq) ?>店铺信息
                    </div>
                    <div class="layui-card-body layui-text">
                        <img src="http://q1.qlogo.cn/g?b=qq&nk=<?php echo $qq ?>&s=100&t=1547904810" width="50" height="50"/>
                        <hr>
                        已上架商品：<?php echo round($sjjscount,2) ?>件<br>
                        当前商品已购买人数：<?php echo $row['count'] ?>人
                        <hr>
                        <p lay-tips="用户编号可用来投诉商品">卖家用户编号：<?php echo $row['uid'] ?></p>
                        卖家入驻时间：<?php echo $user['addtime'] ?><hr>
                        <div class="layui-elem-quote">商品认证状态：<?php echo $text ?></div>
                        <div class="layui-elem-quote">店铺星级：<div id="grade"></div></div>
                        <p><a href="./user_details.php?uid=<?php echo $row['uid'] ?>" title="<?php echo $row['uid'] ?>的主页">访问店铺主页</a></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12">
            <div class="layadmin-homepage-panel layadmin-homepage-shadow">
                <div class="layui-card">
                    <div class="layui-card-header">
                        商品详情
                    </div>
                <ul class="layadmin-homepage-list-group">
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-triangle-r"></i>
                            <span style="word-wrap:break-word;">适用系统：<?php echo $system ?></span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-code-circle"></i>
                            <span style="word-wrap:break-word;">商品类别：<?php echo $type_name ?></span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-circle-dot"></i>
                            <span style="word-wrap:break-word;">商品编号：<?php echo $id ?></span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-rmb"></i>
                            <span style="word-wrap:break-word;">商品售价：<?php echo $row['money'] ?>元</span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-user"></i>
                            <span style="word-wrap:break-word;">投稿用户：<a href="user_details.php?uid=<?php echo $row['uid'];?>" title="<?php echo qqname($qq) ?>的主页"><?php echo qqname($qq) ?></a></span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" style="color:#FF9100">
                            <i class="layui-icon layui-icon-rmb"></i>
                            <span style="word-wrap:break-word;">我的余额：<?php echo $userrow['rmb'] ?>元</span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-about"></i>
                            <span style="word-wrap:break-word;">商品版本：<?php echo $row['version'] ?>版本 - <a href="javascript:layer.alert('<?php echo $row['updatelog'] ?>',{title:'版本日志'})">查看日志</a></span>
                        </a>
                    </li>
                    <li class="list-group-item">
                        <a href="javascript:;" class="color">
                            <i class="layui-icon layui-icon-date"></i>
                            <span style="word-wrap:break-word;">投稿时间：<?php echo $row['sjdate'] ?></span>
                        </a>
                    </li>
                </ul>
            </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 ">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="layui-icon layui-icon-praise"></i>赞过的人
                </div>
                <div class="layui-card-body">
                    <div class="layui-row">
                        <?php
                        $rs=$DB->query("SELECT * FROM authguao_praise WHERE tid='{$id}' order by id asc");
                        while($res = $DB->fetch($rs))
                        {
                        if ($res['uid'] == 1) {
                            if($conf['admin_qq']){
                                $uqq=$conf['admin_qq'];
                            }else{
                                $uqq=$conf['kfqq'];
                            }
                            $img = 'http://q1.qlogo.cn/g?b=qq&nk='.$uqq.'&s=100&t=1547904810';
                            $status_name = qqname($uqq);
                            $msg = 'user_details.php?uid='.$res['uid'];
                        } else {
                            $users = $DB->get_row("select * from authguao_user where uid='" . $res['uid'] . "' limit 1");
                            $uqq = $users['qq'];
                            if ($users['status'] != 1) {
                                $img = '../assets/img/active.png';
                                $status_name = '已封禁账号';
                                $msg = "javascript:layer.msg('该用户因为违规，已被管理员禁封!')";
                            } else {
                                $img = 'http://q1.qlogo.cn/g?b=qq&nk='.$uqq.'&s=100&t=1547904810';
                                $status_name = qqname($uqq);
                                $msg = 'user_details.php?uid='.$res['uid'];
                            }
                        }
                        echo '<div class="layui-col-xs4 layui-col-sm3 layui-col-md2 layui-col-lg1">
                            <div class="layui-card" style="border-radius:1rem;">
                                <img src="'.$img.'" style="border-radius: 10rem;display: block;margin: auto;width: 3rem;height:3rem" />
                                <div class="layui-text layui-elip" style="text-align: center;height:2rem"><a href="'.$msg.'" title="'.$status_name.'的主页">'.$status_name.'</a></div>
                            </div>
                        </div>';
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script src="https://cdn.staticfile.org/Swiper/4.5.1/js/swiper.min.js"></script>
<script>
layui.use('rate', function () {
    var rate = layui.rate;
    var ins1 = rate.render({elem: '#grade', value: 2.5, text: true, half: true, readonly: true});
});
var swiper = new Swiper('.swiper-container', {
    slidesPerView: 1,
    spaceBetween: 30,
    loop: true,
    pagination: {
        el: '.swiper-pagination',
        dynamicBullets: true,
    }
});
function lat() {
    layer.photos({
        photos: '#layer-photos-demo', 
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });
}
function image_msg(id) {
    $.getJSON('../ajax.php?act=image_shop&id=' + id, function (json) {
        layer.photos({photos: json, anim: 5});
    });
}
function store_log(id) { //购买商品
    layer.open({
        tltle: '请选择付款方式!',
        content: '请点击下方按钮选择付款方式!,若是免费商品随意点击即可',
        icon: 3,
        btn: ['取消', '余额购买'],
        btn2: function (layero, index) {
            ajaxs(id);
        },
    })
}
function ajaxs(id) {
    var index = layer.msg('正在购买中...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "post",
        url: "ajax.php?act=store_log",
        async: true,
        data: {id: id},
        typeData: 'json',
        success: function (data) {
            if (data.code == 0) {
                layer.close(index);
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.close(index);
                layer.msg(data.msg, {btn: '好吧Q_Q', time: 88888});
            }
        }, error: function (data) {
            layer.msg('加载失败!', {icon: 5});
        }
    });
}
<?php if ($shop_log) {?>
function upaet(id) { //获取下载地址
    var index = layer.msg('正在获取商品信息...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "post",
        url: "ajax.php?act=store_update",
        async: true,
        data: {id: id},
        typeData: 'json',
        success: function (data) {
            layer.close(index);
            if (data.code == 0) {
                layer.alert(data.msg, {
                    icon: 1, title: '商品下载地址获取成功', btn: ['<a href=' + data.url + '>下载商品文件</a>', '取消']
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        }, error: function (data) {
            layer.msg('加载失败!');
        }
    });
}
<?php }?>
<?php if(!$rows){?>
function praise(id) { //点赞
    var index = layer.msg('正在为您所喜欢的商品点赞...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "post",
        url: "ajax.php?act=praise",
        async: true,
        data: {id: id},
        typeData: 'json',
        success: function (data) {
            if (data.code == 0) {
                layer.close(index);
                layer.msg(data.msg, {
                    icon: 6, end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.close(index);
                layer.msg(data.msg, {icon: 5});
            }
        }, error: function (data) {
            layer.msg('加载失败!', {icon: 5});
        }
    });
}
<?php }?>
</script>
<?php
}else{
    sysmsg("参数错误",2,'./',true);
}
?>